"""
Copyright 2009, Jay Shurtz.

This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.

Base class for all hatch target interfaces to the physical 
implementation of a hatch design.  In the case of an FPGA using a serial port, 
the serial interface class would inherit from the base target class here.  
The same would go for an IC using a usb port, etc.
"""  

id = "$Id: hatch_target.py 678 2010-07-09 01:44:17Z jayshurtz $"
# $URL: https://hatch.googlecode.com/svn/trunk/hatch_interface/hatch_target.py $
# $Author: jayshurtz $
version = " ".join(id.split()[1:3])


import to_hatch_structure
import hatch_easy_logger


ERROR_PORT = 38


class HatchPortError(IOError):
    """ Raise a generic exception for all port types (serial, parallel, etc.)
    """
    pass


class HatchPortWrapper(hatch_easy_logger.EasyLogger):
    """ Super class for all hatch target classes to inherit from.
        This class is not meant to be instantiated, instead a
        "hatch_serial" object or other class would be used.
    """
    NOT_IMPLEMENTED = "Not implemented, use a child class"

    def __init__(self, unique=None, logHandlers=[]):
        """ 'unique' is any string that is unique for this instance. 
            This is used to set up a unique logger/logging channel.
            'logHandlers' is a list of additional log handlers (such as 
            logging.FileHandler instances). 
        """
        hatch_easy_logger.EasyLogger.__init__(self, unique, logHandlers)    # Create self.logger.

    def open(self):
        """ Open device port.
        """
        raise NotImplementedError, NOT_IMPLEMENTED

    def close(self):
        """ Close device port.
        """
        raise NotImplementedError, NOT_IMPLEMENTED

    def inWaiting(self):
        """ Return the number of characters in the device port buffer.
        """
        raise NotImplementedError, NOT_IMPLEMENTED
    
    def flushOutput(self):
        """ Flush device output buffer.
        """
        raise NotImplementedError, NOT_IMPLEMENTED
    
    def flushInput(self):
        """ Flush device input buffer.
        """
        raise NotImplementedError, NOT_IMPLEMENTED

    def write(self, value):
        """ Write to the port.
        """
        raise NotImplementedError, NOT_IMPLEMENTED

    def read(self, length=None):
        """ Read from the port.
        """
        raise NotImplementedError, NOT_IMPLEMENTED


# Main for testing.
if __name__ == "__main__":
    
    pass

